// 1. 引入函数
import { defineStore } from 'pinia';
import { reqGetCategory1ListData, reqGetCategory2ListData, reqGetCategory3ListData } from '@/api/product/categorySelector'
import type {categoryInfoStoreModel } from '@/api/product/model/categorySelectorModel'
// 2. 创建模块实例对象
export const useCategorySelectorInfoStore = defineStore('categorySelectorInfo', {
  state: ():categoryInfoStoreModel  => {
    return {
      // 需要三个数组 分别存储各种分类数据
      category1List: [],
      category2List: [],
      category3List: [],
      // 需要三个id 后面会用到
      category1Id: undefined,
      category2Id: undefined,
      category3Id: undefined
    }
  },
  actions: {
    async getCategory1ListData() {
      const result:any = await reqGetCategory1ListData()
      this.category1List = result
    },
    async getCategory2ListData(val:number) {
      const result:any = await reqGetCategory2ListData(val)
      this.category1Id=val
      this.category2Id=undefined
      this.category3Id=undefined
      this.category2List = result
      this.category3List=[]
    },
    async getCategory3ListData(val:number) {
      const result:any = await reqGetCategory3ListData(val)
      this.category2Id=val
      this.category3Id=undefined
      this.category3List = result
    },
    setCategory3Id(val:number){
      this.category3Id=val
    }
  }
})